//
//  BDJNavigationController.m
//  BuDeJie
//
//  Created by TFAppleWork-Summer on 2018/3/20.
//  Copyright © 2018年 TFAppleWork-Summer. All rights reserved.
//

#import "BDJNavigationController.h"
#import "UIBarButtonItem+item.h"
@interface BDJNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation BDJNavigationController

+(void)load{
    UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[self class]]];
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    [attrs setValue:[UIFont boldSystemFontOfSize:20] forKey:NSFontAttributeName];
    [navBar setTitleTextAttributes:attrs];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    /*
     1 恢复滑动返回
     delegate设置为self ,然后再代理方法中设置手势什么时候出发：导航的根控制器不会出发，导航的其他控制器都可以触发
     */
//    self.interactivePopGestureRecognizer.delegate = self;
    
    /*
     2 为什么导航控制器的手势滑动返回的手势不是全屏的 => 导航控制器的滑动手势是UIScreenEdgePanGestureRecognizer =>给导航控制器添加新的手势
     
     方法一 ：
     UIScreenEdgePanGestureRecognizer *edgePan =(UIScreenEdgePanGestureRecognizer *) self.interactivePopGestureRecognizer;
     edgePan.edges = UIRectEdgeNone; （无效）
     */
    // 方法二 ：
    
//    // 静止之前的手势
    self.interactivePopGestureRecognizer.enabled = NO;

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self.interactivePopGestureRecognizer.delegate    action:@selector(handleNavigationTransition::)];
     pan.delegate = self;
    [self.view addGestureRecognizer:pan];
    
    
    
    
}

-(void)pan:(UIGestureRecognizer*)pan{
    
    NSLog(@"1111111");
}
 /*
  恢复滑动返回功能 -> 分析：把系统的返回按钮覆盖 ->
  1.手势失效
        1.手势清空？ ->并不是
        2.手势代理中的处理导致手势失效？ ->是的，所以将代理清空
        3.假死状态：程序在运行，但是死了，
  */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    if (self.viewControllers.count>0) {
       
        
        // 设置返回按钮(非根控制器需要判断)
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem
                                                           backItemWithImage:[UIImage imageNamed:@"navBackNor"]
                                                           highImage:[UIImage imageNamed:@"navBackSel"]
                                                           target:self
                                                           action:@selector(back)
                                                           title:@"返回"];
    }
    [super pushViewController:viewController animated:animated];
    
}

-(void)back{
    [self popViewControllerAnimated:YES];
}


#pragma mark - UIGestureRecognizerDelegate
// 是否出发手势
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(nonnull UITouch *)touch{
    if (self.viewControllers.count>1) {
        NSLog(@"%@",gestureRecognizer);
        return YES;
    }
    return NO;
}
/*
 导航控制器的手势如下：
 <UIScreenEdgePanGestureRecognizer: 0x7f9f11c2fa40; state = Possible; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x7f9f11d39350>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7f9f11c2f620>)>>
 */

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
